<!DOCTYPE html>
<html>
  <head><meta name="generator" content="Hexo 3.9.0">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    
    <meta name="theme-color" content="#33363b">
    <meta name="msapplication-TileColor" content="#33363b">
    
    
    
    
    <meta name="keywords" content="GCU, ACM, Algorithm">
    
    
    <link rel="apple-touch-icon" sizes="180x180" href="/favicons/apple-touch-icon.png">
    
    
    <link rel="icon" type="image/png" sizes="192x192" href="/favicons/android-chrome-192x192.png">
    
    
    <link rel="icon" type="image/png" sizes="32x32" href="/favicons/favicon-32x32.png">
    
    
    <link rel="icon" type="image/png" sizes="16x16" href="/favicons/favicon-16x16.png">
    
    
    <link rel="mask-icon" href="/favicons/safari-pinned-tab.svg" color="#33363b">
    
    
    <link rel="manifest" href="/favicons/site.webmanifest">
    
    
    <meta name="msapplication-config" content="/favicons/browserconfig.xml">
    
    
    <link rel="alternate" href="/atom.xml" title="GCU-ACM" type="application/atom+xml">
    
    
    <link rel="shortcut icon" type="image/x-icon" href="/favicons/favicon.ico">
    
    
    <link rel="stylesheet" type="text/css" href="/css/normalize.css">
    <link rel="stylesheet" type="text/css" href="/css/index.css">
    
    <link rel="stylesheet" type="text/css" href="/css/sidebar.css">
    
    
<link rel="stylesheet" type="text/css" href="/css/page.css">
<link rel="stylesheet" type="text/css" href="/css/post.css">

    <link rel="stylesheet" type="text/css" href="/css/custom.css">
    <link rel="stylesheet" type="text/css" href="/css/atom-one-dark.css">
    <link rel="stylesheet" type="text/css" href="/css/lightgallery.min.css">
    <script type="text/javascript" src="/js/jquery.min.js"></script>
    <script defer type="text/javascript" src="/js/util.js"></script>
    <script defer type="text/javascript" src="/js/clipboard.min.js"></script>
    <script defer type="text/javascript" src="/js/scrollspy.js"></script>
    <script defer type="text/javascript" src="/js/fontawesome-all.min.js"></script>
    <script defer type="text/javascript" src="/js/lightgallery.min.js"></script>
    <script defer type="text/javascript" src="/js/lg-fullscreen.min.js"></script>
    <script defer type="text/javascript" src="/js/lg-hash.min.js"></script>
    <script defer type="text/javascript" src="/js/lg-pager.min.js"></script>
    <script defer type="text/javascript" src="/js/lg-thumbnail.min.js"></script>
    <script defer type="text/javascript" src="/js/lg-zoom.min.js"></script>
    
    <script defer src="/js/busuanzi.pure.mini.js"></script>
    
    
    <script defer type="text/javascript" src="/js/search.js"></script>
    <script type="text/javascript">
    $(document).ready(function () {
      var searchPath = "search.xml";
      if (searchPath.length === 0) {
        searchPath = "search.xml";
      }
      var path = "/" + searchPath;
      searchFunc(path, "search-input", "search-result");
    });
    </script>
    
    
    
    <script defer type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-MML-AM_CHTML"></script>
    <script type="text/x-mathjax-config">
    MathJax.Hub.Config({
      tex2jax: {
        inlineMath: [ ["$","$"], ["\\(","\\)"]  ],
        processEscapes: true,
        skipTags: ["script", "noscript", "style", "textarea", "pre", "code"]
      }
    });
    </script>
    <script type="text/x-mathjax-config">
    MathJax.Hub.Queue(function() {
      var all = MathJax.Hub.getAllJax(), i;
      for (i=0; i < all.length; i += 1) {
        all[i].SourceElement().parentNode.className += " has-jax";
      }
    });
    </script>
    
    
    <script defer type="text/javascript" src="/js/index.js"></script>
    <script type="text/javascript">
    $(document).ready(function () {
      var cb = null;
      var els = $(".post figure.highlight");
      if (els.length) {
        // Enabled Hexo highlight line number.
        $(els).each(function (i, e) {
          $(e).before("<button class=\"copy button\">複製</button>");
        });
        cb = new ClipboardJS("button.copy", {
          "target": function (trigger) {
              // Get target element by DOM API.
              // nextElementSibling is figure,highlight.
              // And following is the sequence of Hexo's internal
              // highlight layout with line number.
              return trigger.nextElementSibling.firstChild.firstChild.firstChild.lastChild.firstChild.firstChild;
          }
        });
      } else {
        // Disabled Hexo highlight line number.
        els = $(".post pre code");
        $(els).each(function (i, e) {
          // Add button before pre, not code.
          $(e).parent().before("<button class=\"copy button\">複製</button>");
        });
        cb = new ClipboardJS("button.copy", {
          "target": function (trigger) {
              // Get target element by DOM API.
              // nextElementSibling is figure,highlight.
              // And following is the sequence of Hexo's internal
              // highlight layout without line number.
              return trigger.nextElementSibling.firstChild;
          }
        });
      }
      cb.on("success", function (e) {
        e.clearSelection();
        var trigger = e.trigger;
        // Change button text as a user tip.
        trigger.innerHTML = "已複製";
        $(trigger).addClass("copied");
        // Change button text back;
        setTimeout(function () {
          trigger.innerHTML = "複製";
          $(trigger).removeClass("copied");
        }, 1500);
      });
    });
    </script>
    
    <script defer type="text/javascript" src="/js/custom.js"></script>
    <title>2018六月月赛 | GCU-ACM - Talk is cheap,show me your code</title>
  </head>
  <body itemscope itemtype="http://schema.org/WebPage" lang="zh_CN" data-spy="scroll" data-target=".list-group">
    
<header id="header" class="header" style="background: #33363b;">
  <div class="container">
    <div class="header-container">
      <div class="header-title">
        <h1 class="title"><a href="/">GCU-ACM</a></h1>
        <h2 class="subtitle">Talk is cheap,show me your code</h2>
      </div>
      
      <div class="logo">
        <img src="/images/logo.png" alt="logo">
      </div>
      
    </div>
    <nav id="nav" class="nav">
      <a id="nav-toggle" class="nav-toggle" aria-hidden="true"><i class="fas fa-bars" aria-label="切换导航栏"></i></a>
      <ul id="menu" role="menubar" aria-hidden="false">
        
        <li role="menuitem"><a href="/"><i class="fas fa-home"></i><span class="menu-text">首页</span></a></li>
        
        <li role="menuitem"><a href="/archives/"><i class="fas fa-archive"></i><span class="menu-text">归档</span></a></li>
        
        <li role="menuitem"><a href="/categories/"><i class="fas fa-th-list"></i><span class="menu-text">分类</span></a></li>
        
        <li role="menuitem"><a href="/tags/"><i class="fas fa-tags"></i><span class="menu-text">标签</span></a></li>
        
        <li role="menuitem"><a href="/about/"><i class="fas fa-user-edit"></i><span class="menu-text">关于</span></a></li>
        
        <li role="menuitem"><a href="http://gcuacm.gitee.io/new2018"><i class="far fa-hand-rock"></i><span class="menu-text">招新</span></a></li>
        
      </ul>
    </nav>
  </div>
</header>


    <main id="main" class="main">
      <div class="container">
        <div class="main-container">
          <div class="content">
            
<div id="post" class="page">
  
  <article class="article post card" itemscope itemtype="http://schema.org/Article">
    <div class="post-block">
      <link itemprop="mainEntityOfPage" href="http://yoursite.com/2018/06/24/yuesai-18-06/">
      <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
       <meta itemprop="name" content="码到成功">
       <meta itemprop="description" content="除非你能在床上赚钱，否则就不要赖在床上">
       <meta itemprop="image" content="/images/avatar.png">
      </span>
      <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
       <meta itemprop="name" content="GCU-ACM">
      </span>
    </div>
    <header class="post-header">
      <h1 class="post-title" itemprop="name headline">2018六月月赛</h1>
      <div class="post-meta">
        
        <span class="post-date">
          <i class="far fa-calendar-plus"></i><span><time title="post-date" itemprop="dateCreated datePublished" datetime="2018-06-24T19:36:59+08:00">2018-06-24 19:36:59</time></span>
        </span>
        
        
        
        <span class="post-meta-divider divider">|</span>
        
        <span class="post-categories">
          
          <i class="far fa-folder-open"></i><span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/categories/教学/" itemprop="url" rel="index"><span itemprop="name">教学</span></a></span>
        </span>
        
        
        
        
      </div>
    </header>
    <main class="post-main" itemprop="articleBody">
      <p>2018六月月赛</p>
<hr>
<p>作者：老陈</p>
<a id="more"></a>
<h1 id="四边形"><a href="#四边形" class="headerlink" title="四边形"></a>四边形</h1><p><strong>题目描述</strong><br>老陈最近遇到了一个问题，他想计算一个四边形的面积。但是由于他遇到的四边形都是奇形怪状的所以他不想动手算了。你能否写一个程序帮他完成计算？</p>
<p><strong>输入</strong><br>输入共四行，每行代表四边形的其中一个顶点的坐标。</p>
<p><strong>输出</strong><br>输出一个数代表这四个点围成的四边形的面积，保留三位小数。</p>
<p><strong>样例输入</strong><br>2 2<br>2 -2<br>-2 2<br>-2 -2 </p>
<p><strong>样例输出</strong><br>16.000</p>
<p><strong>思路</strong><br>利用割补法进行计算。</p>
<p><strong>参考代码</strong><br>略</p>
<h1 id="悬崖"><a href="#悬崖" class="headerlink" title="悬崖"></a>悬崖</h1><p><strong>题目描述</strong><br>老陈某天夜里，做了一场噩梦。他梦见他受到了无数个无形的力的作用。而他的前方Y米处是一处悬崖。此时他会受到这些力作用M秒，在这段时间内老陈无法做出任何动作，这些力也不会发生改变。<br>他想知道，M秒过后，他会不会掉下悬崖。</p>
<p><strong>输入</strong><br>第一行包含三个正整数N、M、Y，分别表示老陈受到的力的个数、受到这些力的时间、老陈离悬崖的距离。（$1≤N≤10^5, 0≤M≤10^5,1≤Y≤10^9$）<br>接下来N行，每行输入一个力的信息。这些力的表示均使用向量表示。老陈位于原点，悬崖在老陈的y轴方向。 </p>
<p><strong>输出</strong><br>若老陈在M秒后会掉下悬崖，输出”Die”；否则输出”Save”。</p>
<p><strong>样例输入</strong><br>3 8 5<br>1 1 0<br>-1 0 0<br>0 -1 0</p>
<p><strong>样例输出</strong><br>Save</p>
<p><strong>思路</strong></p>
<p><img src="https://gitee.com/wyatt17/blog_image/raw/master/6%E6%9C%88%E6%9C%88%E8%B5%9B.png" alt></p>
<p><strong>参考代码</strong><br><figure class="hljs highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><code class="hljs c++"><span class="hljs-function"><span class="hljs-keyword">int</span> <span class="hljs-title">main</span><span class="hljs-params">()</span><br></span>&#123;<br>	<span class="hljs-keyword">int</span> n, m, total_y = <span class="hljs-number">0</span>;<br>	ll k;<br>	<span class="hljs-built_in">cin</span> &gt;&gt; n &gt;&gt; m &gt;&gt; k;<br>	<span class="hljs-keyword">for</span> (<span class="hljs-keyword">int</span> i = <span class="hljs-number">0</span>; i &lt; n; i++)<br>	&#123;<br>		<span class="hljs-keyword">int</span> x, y, z;<br><br>		<span class="hljs-built_in">cin</span> &gt;&gt; x &gt;&gt; y &gt;&gt; z;<br>		total_y += y;<br>	&#125;<br>	<span class="hljs-keyword">if</span> (k - (ll)m*total_y &lt;= <span class="hljs-number">0</span>)<br>		<span class="hljs-built_in">cout</span> &lt;&lt; <span class="hljs-string">"Die"</span>;<br>	<span class="hljs-keyword">else</span><br>		<span class="hljs-built_in">cout</span> &lt;&lt; <span class="hljs-string">"Save"</span>;<br><span class="hljs-keyword">return</span> <span class="hljs-number">0</span>;<br>&#125;<br></code></pre></td></tr></table></figure></p>
<h1 id="反模幂运算"><a href="#反模幂运算" class="headerlink" title="反模幂运算"></a>反模幂运算</h1><p><strong>题目描述</strong></p>
<p>我们知道，计算$2^n\mod m$是一个著名的问题。快速解决这个问题的算法是RSA加密算法的核心之一。<br>现在，我们想解决与问题“相反”的另一个问题：计算$m \mod2^n$<br>请你完成这个问题。</p>
<p><strong>输入描述</strong><br>仅包含两个正整数n、m。（$1≤n,m≤10^8$)</p>
<p><strong>输出描述</strong><br>输出一个整数，代表$m \mod2^n$的值。</p>
<p><strong>样例输入</strong><br>4 42</p>
<p><strong>样例输出</strong><br>10</p>
<p><strong>思路</strong><br>注意数据范围！$n≤10^8$<br>你能计算$2^{100000000}$吗？<br>当然不可能！<br>那么怎么办呢？<br>回到数据范围，m的范围也是最大为$10^8$<br>计算器算一下，我们知道m不会大于$2^{27}$。那么，如果n大于27的话，很明显，最终式子的最终结果是m。如果n不大于27，我们就老老实实模一下就行了。（反正不会超过int范围）</p>
<p><strong>参考代码</strong><br><figure class="hljs highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs c++"><span class="hljs-function"><span class="hljs-keyword">int</span> <span class="hljs-title">main</span><span class="hljs-params">()</span><br></span>&#123;<br>	<span class="hljs-keyword">int</span> n, m;<br>	<span class="hljs-built_in">scanf</span>(<span class="hljs-string">"%d%d"</span>, &amp;n, &amp;m);<br>	<span class="hljs-keyword">if</span> (n &gt; <span class="hljs-number">27</span>)<br>		<span class="hljs-built_in">printf</span>(<span class="hljs-string">"%d"</span>, m);<br>	<span class="hljs-keyword">else</span><br>		<span class="hljs-built_in">printf</span>(<span class="hljs-string">"%d"</span>, m % (<span class="hljs-keyword">int</span>)<span class="hljs-built_in">pow</span>((<span class="hljs-keyword">double</span>)<span class="hljs-number">2</span>, (<span class="hljs-keyword">double</span>)n)); <span class="hljs-keyword">return</span> <span class="hljs-number">0</span>;<br>&#125;<br></code></pre></td></tr></table></figure></p>
<h1 id="闯关"><a href="#闯关" class="headerlink" title="闯关"></a>闯关</h1><p><strong>题目描述</strong><br>玩家A和玩家B现在正在魔塔中闯关。这座魔塔共有X层，要想打败这一层的领主才能前往下一关。<br>玩家A和玩家B很菜，他们自身的攻击力连第一层的领主都打不过。所以他们想到了另外一种方法：利用领主害怕的符咒来杀死领主。玩家A和玩家B的背包中都有一定数量的符咒并且玩家A拥有一个可以使用Y次的符咒转换器，它能够将任意一张符咒转换为另一张符咒。<br>现在他们准备出发了，请你判断下他们能否成功通关。</p>
<p><strong>输入描述</strong><br>第一行包含两个正整数X、Y，分别代表魔塔的层数和符咒转换器的使用次数。（$1≤x,y≤10^5$)<br>第二行代表玩家A中拥有的符咒的情况，其中第一个数代表玩家A拥有的符咒的数量。其后有个正整数，代表第i个符咒能作用于第i层的领主上。<br>第三行代表玩家B中拥有的符咒的情况，形式与第二行相同。</p>
<p><strong>输出描述</strong><br>如果他们能够通关，输出“Yes”，然后空一个空格后输出使用符咒转换器的次数；如果他们无法通关，输出“No”。</p>
<p><strong>样例输入</strong><br>5 3<br>4 1 2 2 2<br>2 4 5</p>
<p><strong>样例输出</strong><br>Yes 1</p>
<p><strong>思路</strong><br>我们考虑一下使用符咒转换器的条件：</p>
<ol>
<li>缺少打败某层的领主的符咒</li>
<li>有某个领主的符咒超过一张<br>那么，我们统计一下一共有几种符咒，并统计其中可以拿来转换的符咒的数量。</li>
</ol>
<p>如果转换之后能补齐，那么就是Yes，而使用的次数就是之前缺失的符咒的张数。<br><strong>Set简介</strong><br>Set是一个重要的容器。Set，顾名思义就是集合。<br>学过数学，我们知道，集合满足不重复性。所以Set的一个特点是不允许有重复元素。<br>对于这道题，我们可以使用Set来存储这些符咒。在保存之前，我们需要判断一下它是否已经存在于Set中。如果存在，就是可以拿来转换的符咒。<br>在存储完之后，我们使用size函数获得Set中的元素个数。也就获得了有多少种不同的符咒<br>然后再判断多余的能否转换补齐剩下的即可。</p>
<p><strong>参考代码</strong><br><figure class="hljs highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><code class="hljs c++"><span class="hljs-function"><span class="hljs-keyword">int</span> <span class="hljs-title">main</span><span class="hljs-params">()</span><br></span>&#123;<br>	<span class="hljs-built_in">set</span>&lt;<span class="hljs-keyword">int</span>&gt;fu;<br>	<span class="hljs-keyword">int</span> n, m;<br>	<span class="hljs-keyword">int</span> k = <span class="hljs-number">0</span>;<br>	<span class="hljs-built_in">cin</span> &gt;&gt; n &gt;&gt; m;<br>	<span class="hljs-keyword">for</span> (<span class="hljs-keyword">int</span> i = <span class="hljs-number">0</span>; i &lt; <span class="hljs-number">2</span>; i++)<br>	&#123;<br>		<span class="hljs-keyword">int</span> t;<br>		<span class="hljs-built_in">cin</span> &gt;&gt; t;<br>		<span class="hljs-keyword">for</span> (<span class="hljs-keyword">int</span> j = <span class="hljs-number">0</span>; j &lt; t; j++)<br>		&#123;<br>			<span class="hljs-keyword">int</span> x;<br>			<span class="hljs-built_in">cin</span> &gt;&gt; x;<br>			<span class="hljs-keyword">if</span> (!fu.insert(x).second)<br>				k++;<br>		&#125;<br>	&#125;<br>	k = min(k, m);<br>	<span class="hljs-keyword">if</span> (fu.size() + k &gt;= n)<br>	&#123;<br>		<span class="hljs-built_in">cout</span> &lt;&lt; <span class="hljs-string">"Yes "</span> &lt;&lt; n - fu.size();<br>	&#125;<br>	<span class="hljs-keyword">else</span><br>		<span class="hljs-built_in">cout</span> &lt;&lt; <span class="hljs-string">"No"</span>;<br><span class="hljs-keyword">return</span> <span class="hljs-number">0</span>;<br>&#125;<br></code></pre></td></tr></table></figure></p>
<h1 id="最小数-amp-最大数"><a href="#最小数-amp-最大数" class="headerlink" title="最小数&amp;最大数"></a>最小数&amp;最大数</h1><p><strong>题目描述</strong><br>小陈正在和他的朋友玩猜数游戏，小陈写了一个数字后告诉朋友这个数的位数和这个数的所有的位的和。<br>请你计算一下他的朋友可以猜的数的范围。<br>只包含两个数a、b，分别代表小陈所写的数的位数和这个数的所有的位的和。（1≤a≤100,0≤b≤900）</p>
<p><strong>输出</strong><br>输出两个正整数，分别代表他的朋友所猜的数的最小值和最大值。<br>如果不存在符合情况的数，输出“-1 -1”。</p>
<p><strong>样例输入</strong><br>2 15</p>
<p><strong>样例输出</strong><br>69 96</p>
<p><strong>思路</strong><br>这题比较恶心。<br>细节多。<br>首先，当总和大于位数*9或者位数大于1但是和为0的时候，就只能输出”-1 -1”了。（注意当位数为1时存在总和为0的情况），然后，确保存在之后，我们确定最大最小值即可。</p>
<p>最大值比较简单，把所有能组成的9放在前面，最后剩下多少就接在9的后面，如果现在位数还不够的话后面补0就行了。<br>例如：<br><code>14 92</code><br>我们能弄出10个9，最后剩下一个2。然后现在总共11位，还差3位，那就最后补3个0就是了。即<code>99999999992000</code>。</p>
<p>最小值比较麻烦，我们首先要跟最大值反着来。<br>把所有的9放在最后面，最后剩下多少就放在最前面。如果位数不够，那么现在最前面的那个数要减一，然后前面补1000……直到位数足够。</p>
<p>还是上面的那个例子：<br>我们将10个9放在最后，剩下2放在最前面。<br>即<code>29999999999</code>。<br>但是现在只有11位，那么最前面的那一位就要减一。<br>即 <code>19999999999</code>。<br>然后前面用1000……接上直到位数足够。<br>即 <code>10019999999999</code>。<br>按照上面的思路写就完成了。</p>
<p><strong>参考代码</strong><br><figure class="hljs highlight C++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br></pre></td><td class="code"><pre><code class="hljs C++"><span class="hljs-function"><span class="hljs-keyword">int</span> <span class="hljs-title">main</span><span class="hljs-params">()</span><br></span>&#123;<br>	<span class="hljs-keyword">int</span> len, sum;<br>	<span class="hljs-built_in">cin</span> &gt;&gt; len &gt;&gt; sum;<br>	<span class="hljs-keyword">int</span> max[<span class="hljs-number">110</span>] = &#123; <span class="hljs-number">0</span> &#125;;<br>	<span class="hljs-keyword">int</span> min[<span class="hljs-number">110</span>] = &#123; <span class="hljs-number">0</span> &#125;;<br>	<span class="hljs-keyword">int</span> min_pos = len<span class="hljs-number">-1</span>, max_pos = <span class="hljs-number">0</span>;<br>	<span class="hljs-keyword">if</span> ((sum == <span class="hljs-number">0</span>&amp;&amp;len&gt;<span class="hljs-number">1</span>)||sum&gt;len*<span class="hljs-number">9</span>)<br>	&#123;<br>		<span class="hljs-built_in">cout</span> &lt;&lt; <span class="hljs-string">"-1 -1"</span>;<br>		<span class="hljs-keyword">return</span> <span class="hljs-number">0</span>;<br>	&#125;<br>	<span class="hljs-keyword">int</span> i;<br>	<span class="hljs-keyword">for</span> (i = <span class="hljs-number">1</span>; i * <span class="hljs-number">9</span> &lt;= sum; i++)<br>		max[max_pos++] = <span class="hljs-number">9</span>;<br>	i--;<br>	<span class="hljs-keyword">if</span> (sum - i * <span class="hljs-number">9</span>)<br>	&#123;<br>		max[max_pos++] = sum - i * <span class="hljs-number">9</span>;<br>	&#125;<br>	<span class="hljs-keyword">for</span> (i = <span class="hljs-number">1</span>; i * <span class="hljs-number">9</span> &lt;= sum; i++)<br>		min[min_pos--] = <span class="hljs-number">9</span>;<br>	i--;<br>	<span class="hljs-keyword">if</span> (sum - i * <span class="hljs-number">9</span>)<br>	&#123;<br>		min[min_pos] = sum - i * <span class="hljs-number">9</span>;<br>	&#125;<br>	<span class="hljs-keyword">while</span> (min[min_pos] == <span class="hljs-number">0</span>&amp;&amp;min_pos&lt;len<span class="hljs-number">-1</span>)<br>		min_pos++;<br>	<span class="hljs-keyword">if</span> (min[min_pos] &gt; <span class="hljs-number">0</span>&amp;&amp;min[<span class="hljs-number">0</span>]==<span class="hljs-number">0</span>)<br>	&#123;<br>		min[min_pos]--;<br>		min[<span class="hljs-number">0</span>]++;<br>	&#125;<br>	<span class="hljs-keyword">for</span> (i = <span class="hljs-number">0</span>; i &lt; len; i++)<br>		<span class="hljs-built_in">cout</span> &lt;&lt; min[i];<br>	<span class="hljs-built_in">cout</span> &lt;&lt; <span class="hljs-string">' '</span>;<br>	<span class="hljs-keyword">for</span> (i = <span class="hljs-number">0</span>; i &lt; len; i++)<br>	<span class="hljs-built_in">cout</span> &lt;&lt; max[i];<br><span class="hljs-keyword">return</span> <span class="hljs-number">0</span>;<br>&#125;<br></code></pre></td></tr></table></figure></p>

    </main>
    <footer class="post-footer">
      
      <div class="post-tags">
        
        <a class="post-tag button" href="/tags/月赛/" rel="tag"><i class="fas fa-tags"></i>月赛</a>
        
      </div>
      
    </footer>
  </article>
  
  
  <nav class="page-nav">
    <div class="page-nav-next page-nav-item">
      
      <a href="/2018/06/23/queue-BFS/" rel="next" title="队列与BFS"><i class="fas fa-angle-left"></i><span class="nav-title">队列与BFS</span></a>
      
    </div>
    <div class="page-nav-prev page-nav-item">
      
      <a href="/2018/11/08/bufenhe/" rel="prev" title="部分和"><span class="nav-title">部分和</span><i class="fas fa-angle-right"></i></a>
      
    </div>
  </nav>
  
  
  

<div class="comments" id="comments">
  
  
  <div id="vcomments" class="vcomments"></div>
  <script defer src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
  <script defer src="//unpkg.com/valine/dist/Valine.min.js"></script>
  <script type="text/javascript">
  $(document).ready(function () {
    new Valine({
      "el": "#vcomments",
      "appId": "9X1ViI1Sxnb7PFU97Od7SyUu-gzGzoHsz",
      "appKey": "FElrWSPz5YJXJ0PvokRFJDyu",
      "verify": "true",
      "notify": "true",
      "avatar": "mp",
      "meta": ["nick", "mail", "link"],
      "pageSize": 10,
      "lang": "zh-cn",
      "visitor": "false",
      "highlight": "true",
      "placeholder": "😎看了这么多，不想说点什么嘛😉(如果留有邮箱，当被回复时可收到邮件提醒哦)",
      "avatarForce": "false"
    });
  });
  </script>
  
  
</div>



  
</div>

          </div>
          
          
          
<aside class="sidebar" id="sidebar" style="background: url(/images/background.png);">
  
  <div class="search">
    <div class="form-group">
      <i class="fas fa-search"></i><input type="search" id="search-input" name="q" results="0" placeholder="搜索" class="form-control">
    </div>
  </div>
  <div class="search-result-box" id="search-result"></div>
  
  
<div class="info sidebar-item" id="info">
  
  <img class="author-avatar" src="/images/avatar.png" alt="码到成功">
  
  <h1 class="author-name">码到成功</h1>
  <h2 class="author-description">除非你能在床上赚钱，否则就不要赖在床上</h2>
  <div class="site-count">
    
    
    
    
    <div class="archives-count count-block">
      <div class="site-count-title">归档</div>
      <div><a href="/archives/">25</a></div>
    </div>
    
    
    
    <div class="categories-count count-block">
      <div class="site-count-title">分类</div>
      <div><a href="/categories/">4</a></div>
    </div>
    
    
    
    <div class="tags-count count-block">
      <div class="site-count-title">标签</div>
      <div><a href="/tags/">26</a></div>
    </div>
    
    
    
    
    
    
  </div>
  
  <div class="rss">
    <a class="rss-link button sidebar-item" href="/atom.xml"><i class="fas fa-rss"></i>RSS</a>
  </div>
  
</div>


  <div class="sidebar-sticky">
    
    
    
    
    
    <hr>
    <div class="post-toc sidebar-item" id="toc-div">
      <div><i class="fas fa-list-ol"></i>文章目录</div>
      <div class="post-toc-content"><ol class="list-group toc"><li class="toc-item toc-level-1"><a class="list-group-item toc-link" href="#四边形"><span class="toc-text">四边形</span></a></li><li class="toc-item toc-level-1"><a class="list-group-item toc-link" href="#悬崖"><span class="toc-text">悬崖</span></a></li><li class="toc-item toc-level-1"><a class="list-group-item toc-link" href="#反模幂运算"><span class="toc-text">反模幂运算</span></a></li><li class="toc-item toc-level-1"><a class="list-group-item toc-link" href="#闯关"><span class="toc-text">闯关</span></a></li><li class="toc-item toc-level-1"><a class="list-group-item toc-link" href="#最小数-amp-最大数"><span class="toc-text">最小数&amp;最大数</span></a></li></ol></div>
    </div>
    
    
    
    <hr>
    <div class="social-link sidebar-item">
      <div><i class="far fa-address-card"></i>社交链接<p></p></div>
      <ul>
        
        <li><i class="fas fa-envelope"></i><a href="mailto:1239776759@qq.com" target="_blank">E-Mail</a></li>
        
      </ul>
    </div>
    
    
    <hr>
    <div class="blogroll sidebar-item">
      <div><i class="fas fa-link"></i>友情链接</div>
      <ul>
        
        <li><i class="fas fa-link"></i><a href="https://oi-wiki.org/" target="_blank">oi-wiki</a></li>
        
        <li><i class="fas fa-link"></i><a href="https://ac.nowcoder.com/acm/contest/vip-index" target="_blank">牛客竞赛</a></li>
        
        <li><i class="fas fa-link"></i><a href="http://fzcoj.hustoj.com" target="_blank">FZCOJ</a></li>
        
        <li><i class="fas fa-link"></i><a href="https://vjudge.net/article/187" target="_blank">kuangbin带你飞</a></li>
        
        <li><i class="fas fa-link"></i><a href="http://exp-blog.com/2018/06/28/pid-38/" target="_blank">POJ试题分类</a></li>
        
        <li><i class="fas fa-link"></i><a href="https://blog.csdn.net/hbhszxyb/article/details/19845559" target="_blank">OJ(Online Judge)系统及ACM测试题库大全</a></li>
        
      </ul>
    </div>
    
  </div>
</aside>


          
        </div>
      </div>
    </main>
    
<footer id="footer" class="footer" style="background: #33363b;">
  <div class="container">
    <div class="back-to-top">
      <button id="back-to-top"><i class="fas fa-angle-double-up" aria-label="回到顶部"></i></button>
    </div>
    <div class="footer-container">
      <div class="footer-left">
        <div class="copyright">
          <span class="author">码到成功</span><span class="year"><i class="far fa-copyright"></i>2020</span>
        </div>
        
        <div class="busuanzi">
          <span id="busuanzi_container_site_pv"><i class="fas fa-eye" aria-label="站点点击量" aria-hidden="false"></i><span id="busuanzi_value_site_pv"></span></span><span id="busuanzi_container_site_uv"><i class="fas fa-user" aria-label="站点用户数" aria-hidden="false"></i><span id="busuanzi_value_site_uv"></span></span><span id="busuanzi_container_page_pv"><i class="far fa-file-alt"></i><span id="busuanzi_value_page_pv" aria-label="页面点击量" aria-hidden="false"></span></span>
        </div>
        
      </div>
      <div class="footer-right">
        <div class="custom-info">
          
          托管于<i class="fab fa-github-alt"></i><a href="https://gitee.com/help/articles/4136" target="_blank">Gitee Pages</a>
          
        </div>
        <div class="powered-by">
          由 <a href="https://hexo.io/" target="_blank">Hexo</a> 强力驱动 | 主题 <a href="https://github.com/AlynxZhou/hexo-theme-aria/" target="_blank">ARIA</a>
        </div>
      </div>
    </div>
  </div>
</footer>


  </body>
</html>
